import { useMemo } from "react";
import {
  selectGeneralState,
  setLoading,
  setSpinning,
  GeneralState,
} from "@redux/general";
import { useAppDispatch, useAppSelector } from "@redux/hooks";

export const useGeneral = () => {
  const generalState = useAppSelector(selectGeneralState);
  const dispatch = useAppDispatch();

  // eslint-disable-next-line react-hooks/exhaustive-deps
  const setGeneralLoading = (value: GeneralState["loading"]) => {
    dispatch(setLoading(value));
  };

  // eslint-disable-next-line react-hooks/exhaustive-deps
  const setGeneralSpinning = (value: GeneralState["spinning"]) => {
    dispatch(setSpinning(value));
  };

  return useMemo(
    () => ({
      generalState,
      setGeneralLoading,
      setGeneralSpinning,
    }),
    [generalState, setGeneralLoading, setGeneralSpinning]
  );
};
